package com.pandora.common.util;

import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author developer
 */
public class RegexUtil {
    private static final String REGEX_MOBILE = "^((13[0-9])|(14[0-9])|(15([0-9]))|(17([0-9]))|(18[0-9]))\\d{8}$";
    private static final String REGEX_SIMPLE_PASSWORD = "^[a-z|A-Z|\\d]{6,12}$";
    private static final String REGEX_COMPLEX_PASSWORD = "^[a-z|A-Z|\\d|\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\=\\+\\[\\]\\{\\}\\;\\:\\'\\\"\\,\\<\\.\\>\\/\\?]{6,12}$";
    public static final String REGEX_UA_PATTEN = "PandoraCredit/(.*?)\\(";

    /**
     * 验证手机号格式
     * @param mobile 手机号
     * @return true false
     */
    public static boolean isMobile(String mobile){
        return checkRegular(REGEX_MOBILE, mobile);
    }

    /**
     * 验证简单密码格式
     * @param pass 密码
     * @return true false
     */
    public static boolean isSimplePass(String pass){
        return checkRegular(REGEX_SIMPLE_PASSWORD, pass);
    }

    /**
     * 验证复杂密码格式
     * @param pass 密码
     * @return true false
     */
    public static boolean isComplexPass(String pass){
        return checkRegular(REGEX_COMPLEX_PASSWORD, pass);
    }

    /**
     * 校验正则表达式
     * @param regex 正则表达式
     * @param str 需要校验的字符串
     * @return 符合返回true 否则返回false
     */
    public static boolean checkRegular(String regex, String str){
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

    public static List<String> findAllReg(String regex, String str){
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        List<String> objects = new LinkedList<String>();
        while (matcher.find()){
            objects.add(matcher.group());
        }
        return objects;
    }
}
